const app = getApp();
Page({
  data: {
    bindSchoollist:[]
  },

  onLoad: function () {
  },

  onReady: function () {
    
  },

  onShow: function () {
    this.getschoollist()
  },
  /**
  * 生命周期函数--监听页面隐藏
  */
  onHide: function () {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },
// 获取 学校列表
  getschoollist: function () {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    var data={
      'open_id': wx.getStorageSync('openId')
    }
    app.post(app.globalData.serverurl + '/api/user/bindSchoollist', data).then((res) => {
      if (res) {
        that.setData({
          bindSchoollist: res
        })
      }
      wx.hideLoading()
    })
  },

  // choiceschool:function(e){
  //   var cop_id = e.target.id
  //   console.log(cop_id)


  // },
  choiceschool: function (e) {
    var cop_activate = e.currentTarget.dataset.cop_activate
    console.log(cop_activate)
    if (cop_activate == true) {
      wx.switchTab({
        url: '../../pages/index/index',
      })
    }
    else {
      var cop_name = e.currentTarget.dataset.cop_name;
      var cop_id = e.currentTarget.dataset.cop_id;
      var data={
        'open_id': wx.getStorageSync('openId'),
        'cop_id': cop_id
      }
      app.post(app.globalData.serverurl +'/api/user/activate', data).then((res) => {
        console.log(res)
        if (res.status == 'successful'){
          wx.setStorageSync('userId', res.userid)
          wx.setStorageSync('cop_name', res.cop_name)
          wx.setStorageSync('name', res.name)
          wx.setStorageSync('cop_id', res.cop_id)
          wx.switchTab({
            url: '../../pages/index/index',
          })
        }
        else{
          wx.showModal({
            title: '提示',
            content: '切换失败',
          })
        }
        console.log(res);//正确返回结果
      })
      console.log(cop_name)
      // wx.navigateTo({
      //   url: '../../pages/bind/bind?cop_id=' + cop_id + '&schoolname=' + cop_name,
      // })
    }
  },




  /**
 * 页面相关事件处理函数--监听用户下拉动作
 */
onPullDownRefresh: function () {
  this.getschoollist()



  }

})

